package com.xinyan.controller;

//import com.xinyan.config.SprayConfig;
import com.xinyan.plc.RunParam;
import com.xinyan.service.MachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@Controller
public class PageController {

//    @Autowired
//    private SprayConfig sprayConfig;

    @Autowired
    private MachineService machineService;

//    @GetMapping("/index")
//    public String index(Model model) {
//        model.addAttribute("factoryOwner", sprayConfig.getFactoryOwner());
//        model.addAttribute("projectName", sprayConfig.getProjectName());
//        model.addAttribute("converter", sprayConfig.getConverter());
//        model.addAttribute("electricalMachinery", sprayConfig.getElectricalMachinery());
//        model.addAttribute("hmi", sprayConfig.getHmi());
//        return "index";
//    }
//
//    @GetMapping("/getMachineList")
//    public String getMachineList(Model model) {
//        model.addAttribute("list", sprayConfig.getHosts());
//        return "list";
//    }

    @GetMapping("/detail/{id}")
    public String detail(@PathVariable String id, Model model) {
        model.addAttribute("id", id);
        model.addAttribute("id_get", id + "号主机运行参数");
        model.addAttribute("id_set", id + "号主机循环参数设置");
        List<RunParam> list = machineService.readRunParam(Arrays.asList(Integer.valueOf(id)));
//        RunParam runParam = new RunParam();
//        runParam.setVw118(1052);
//        runParam.setVd400(34.0F);
//        runParam.setVd404(10.5F);
//        runParam.setVd408(278.6F);
//        runParam.setVd412(81.8F);
//        runParam.setVd416(3.8F);
        model.addAttribute("runParam", list.get(0));
        List<String> weekList = new ArrayList<>();
        weekList.add("星期日");
        weekList.add("星期一");
        weekList.add("星期二");
        weekList.add("星期三");
        weekList.add("星期四");
        weekList.add("星期五");
        weekList.add("星期六");
        model.addAttribute("weekList", weekList);
        List<Integer> timeList = new ArrayList<>();
        timeList.add(1);
        timeList.add(2);
        timeList.add(3);
        timeList.add(4);
        model.addAttribute("timeList", timeList);
        return "detail";
    }

//    @GetMapping("/favicon.ico")
//    @ResponseBody
//    public void favicon() {
//    }
}
